import { invoke } from '@tauri-apps/api/core';
import { listen } from '@tauri-apps/api/event';

async function install(path) {
    return await invoke('plugin:install|install', {
        payload: {
            path,
        },
    }).then();
}
async function download(url, path, callback) {
    listen('/file/download', async (event) => {
        const { progressTotal, total } = event.payload;
        callback({ progressTotal: progressTotal, total: total });
    });
    return await invoke('plugin:install|download', {
        payload: {
            url, path
        }
    });
}

export { download, install };
